import {
  SET_FILENAME,
  SET_MENUVISIBLE,
  SET_SETTINGVISIBLE,
  SET_DEFAULT_FONTSIZE,
  SET_DEFAULT_FONT_FAMILY,
  SET_FONT_FAMILY_VISIBLE,
  SET_DEFAULT_THEME,
  SET_BOOK_AVAILABLE,
  SET_PROGRESS,
  SET_SECTION,
  SET_IS_PAGINATING,
  SET_CURRENT_BOOK,
  SET_NAVIGATION,
  SET_COVER,
  SET_METADATA,
  SET_PAGINATE,
  SET_PAGELIST,
  SET_OFFSETY,
  SET_IS_BOOKMARK
} from '../mutations-type'

const book = {
  namespaced: true,
  state: () => ({
    fileName: '', // 章节名称
    menuVisible: false, // 菜单显示
    settingVisible: -1, // -1:不显示 0: 字号 1: 主题,2:进度,3:目录
    defaultFontSize: 16, // 默认字体
    defaultFontFamily: 'Default', // 默认字体名称
    fontFamilyVisible: false, // 字体名称是否显示
    defaultTheme: 'Default', // 主题颜色
    bookAvailable: false, // 是否翻页
    progress: 0, // 进度条
    section: 0, // 章节位置
    isPaginating: true, // 是否分页
    currentBook: null, // 当前实例化的书籍
    navigation: null, // 当前的目录
    cover: null, // 书籍封面
    metadata: null, // 书籍信息
    paginate: '',
    pagelist: null, // 页面列表
    offsetY: 0, // 滑动的Y坐标
    isBookmark: null // 是否添加了书签
  }),
  mutations: {
    [SET_FILENAME] (state, fileName) {
      state.fileName = fileName
    },
    [SET_MENUVISIBLE] (state, menuVisible) {
      state.menuVisible = menuVisible
    },
    [SET_SETTINGVISIBLE] (state, settingVisible) {
      state.settingVisible = settingVisible
    },
    [SET_DEFAULT_FONTSIZE] (state, defaultFontSize) {
      state.defaultFontSize = defaultFontSize
    },
    [SET_DEFAULT_FONT_FAMILY]: (state, font) => {
      state.defaultFontFamily = font
    },
    [SET_FONT_FAMILY_VISIBLE]: (state, visible) => {
      state.fontFamilyVisible = visible
    },
    [SET_DEFAULT_THEME]: (state, theme) => {
      state.defaultTheme = theme
    },
    [SET_BOOK_AVAILABLE]: (state, bookAvailable) => {
      state.bookAvailable = bookAvailable
    },
    [SET_PROGRESS]: (state, progress) => {
      state.progress = progress
    },
    [SET_SECTION]: (state, section) => {
      state.section = section
    },
    [SET_IS_PAGINATING]: (state, isPaginating) => {
      state.isPaginating = isPaginating
    },
    [SET_CURRENT_BOOK]: (state, currentBook) => {
      state.currentBook = currentBook
    },
    [SET_NAVIGATION]: (state, navigation) => {
      state.navigation = navigation
    },
    [SET_COVER]: (state, cover) => {
      state.cover = cover
    },
    [SET_METADATA]: (state, metadata) => {
      state.metadata = metadata
    },
    [SET_PAGINATE]: (state, paginate) => {
      state.paginate = paginate
    },
    [SET_PAGELIST]: (state, pagelist) => {
      state.pagelist = pagelist
    },
    [SET_OFFSETY]: (state, offsetY) => {
      state.offsetY = offsetY
    },
    [SET_IS_BOOKMARK]: (state, isBookmark) => {
      state.isBookmark = isBookmark
    }
  },
  actions: {
    setFileName: ({ commit }, fileName) => {
      return commit('SET_FILENAME', fileName)
    },
    setMenuVisible: ({ commit }, setMenuVisible) => {
      return commit('SET_MENUVISIBLE', setMenuVisible)
    },
    setSettingVisible: ({ commit }, settingVisible) => {
      return commit('SET_SETTINGVISIBLE', settingVisible)
    },
    setDefaultFontSize: ({ commit }, defaultFontSize) => {
      return commit('SET_DEFAULT_FONTSIZE', defaultFontSize)
    },
    setFontFamilyVisible: ({ commit }, visible) => {
      return commit('SET_FONT_FAMILY_VISIBLE', visible)
    },
    setDefaultFontFamily: ({ commit }, font) => {
      return commit('SET_DEFAULT_FONT_FAMILY', font)
    },
    setDefaultTheme: ({ commit }, theme) => {
      return commit('SET_DEFAULT_THEME', theme)
    },
    setBookAvailable: ({ commit }, bookAvailable) => {
      return commit('SET_BOOK_AVAILABLE', bookAvailable)
    },
    setProgress: ({ commit }, progress) => {
      return commit('SET_PROGRESS', progress)
    },
    setSection: ({ commit }, section) => {
      return commit('SET_SECTION', section)
    },
    setIsPaginating: ({ commit }, isPaginating) => {
      return commit('SET_IS_PAGINATING', isPaginating)
    },
    setCurrentBook: ({ commit }, book) => {
      return commit('SET_CURRENT_BOOK', book)
    },
    setNavigation: ({ commit }, navigation) => {
      return commit('SET_NAVIGATION', navigation)
    },
    setCover: ({ commit }, cover) => {
      return commit('SET_COVER', cover)
    },
    setMetadata: ({ commit }, metadata) => {
      return commit('SET_METADATA', metadata)
    },
    setPaginate: ({ commit }, paginate) => {
      return commit('SET_PAGINATE', paginate)
    },
    setPagelist: ({ commit }, pagelist) => {
      return commit('SET_PAGELIST', pagelist)
    },
    setIsBookmark: ({ commit }, isBookmark) => {
      return commit('SET_IS_BOOKMARK', isBookmark)
    },
    setOffsetY: ({ commit }, offsetY) => {
      return commit('SET_OFFSETY', offsetY)
    }
  },
  getters: {
    fileName: state => state.fileName,
    menuVisible: state => state.menuVisible,
    settingVisible: state => state.settingVisible,
    defaultFontSize: state => state.defaultFontSize,
    defaultFontFamily: state => state.defaultFontFamily,
    fontFamilyVisible: state => state.fontFamilyVisible,
    defaultTheme: state => state.defaultTheme,
    bookAvailable: state => state.bookAvailable,
    progress: state => state.progress,
    section: state => state.section,
    isPaginating: state => state.isPaginating,
    currentBook: state => state.currentBook,
    navigation: state => state.navigation,
    cover: state => state.cover,
    metadata: state => state.metadata,
    paginate: state => state.paginate,
    pagelist: state => state.pagelist,
    offsetY: state => state.offsetY,
    isBookmark: state => state.isBookmark
  }
}

export default book
